/*
edNLog.js

	edNLog -- the logger itself, with debug(), info(), warning(), error(), and text() methods
	debug -- a convenience method placed in the root to save a few keystrokes for debug method.
	
Example Use:
edNLog.info("Information here!");	
debug("Here's some debug info"); // this is shorthand

*/

var edNLog=new function(){
bPersistState=true;
var sNamespace="ed_log";
var sInstance="edNLog";
var sDOMInstance=sNamespace+"_"+sInstance;
var Config_Enabled=true;
if(Config_Enabled==false&&location.href.match(/edNlog/)){Config_Enabled=true;}
var bLoggerConfigured=false;
var nNumMsgsLogged=0;
function debug(msg,stsk){logMsg("DEBUG",msg,stsk);}
function info(msg,stsk){logMsg("INFO",msg,stsk);}
function warning(msg,stsk){logMsg("WARN",msg,stsk);}
function error(msg,stsk){logMsg("ERROR",msg,stsk);}
function toggleDisplay(){
var oBody=_gE(sDOMInstance+'_body');
if(oBody.style.display=='none'){
oBody.style.display='block';
}else{
oBody.style.display='none';
}
if(bPersistState){
tf.U.setCookie(sInstance+"_visibility",oBody.style.display);
}
}
function clearLog(){
_gE(sDOMInstance+'_logDisplay').innerHTML='';
nNumMsgsLogged=0;
_gE(sDOMInstance+'_handle').innerHTML=nNumMsgsLogged+": Msgs";
}
function enable(){
if(!bLoggerConfigured){
initializeDisplay();
}
}
function text(sText){_gE(sDOMInstance+"_textArea").value=sText;}
this.debug=debug;
this.info=info;
this.warning=warning;
this.error=error;
this.toggleDisplay=toggleDisplay;
this.clearLog=clearLog;
this.text=text;
this.enable=enable;
function logMsg(level,msg,stsk){
if(Config_Enabled){
nNumMsgsLogged+=1;
_gE(sDOMInstance+'_handle').innerHTML=nNumMsgsLogged+": Msgs";
var oDisplay=_gE(sDOMInstance+'_logDisplay');
if(oDisplay.childNodes.length==0){
oDisplay.appendChild(createDisplayRow(level,msg,stsk));
}else{
oDisplay.insertBefore(createDisplayRow(level,msg,stsk),oDisplay.childNodes[0]);
}
}
}
function createDisplayRow(sLevel,sMsg,sTsk){
var oRes=document.createElement("div");
oRes.className="nlRow";
if(nNumMsgsLogged/2!=Math.floor(nNumMsgsLogged/2)){
oRes.style.backgroundColor="#F6F6F6";
}
(sTsk!=undefined)?sTsk=" - "+sTsk:sTsk="";
var oSev=document.createElement("div");
oSev.className="Sev "+sLevel;
oSev.appendChild(document.createTextNode(sLevel+sTsk));
oRes.appendChild(oSev);
var oTime=document.createElement("span");
oTime.style.paddingLeft="3px";
oTime.style.paddingRight="8px";
oTime.appendChild(document.createTextNode(getCurrentTimeFormatted()));
oRes.appendChild(oTime);
oRes.appendChild(document.createTextNode(sMsg));
var oClear=document.createElement("div");
oClear.style.clear="both";
oRes.appendChild(oClear);
return oRes;
}
function getCurrentTimeFormatted(){
var now=new Date();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
var timeValue=""+((hours>12)?hours-12:hours);
if(timeValue=="0")timeValue=12;
timeValue+=((minutes<10)?":0":":")+minutes;
timeValue+=((seconds<10)?":0":":")+seconds;
timeValue+=(hours>=12)?" PM":" AM";
return timeValue;
}
if(Config_Enabled){
initializeDisplay();
}
function initializeDisplay(){
if(!bLoggerConfigured){
try{
var nTop=2;
var nRight=320;
var sDisplay="none";
if(bPersistState){
try{
var sPersistString=tf.U.getCookie(sInstance+"_position");
if(sPersistString!=null){
var aTemp=sPersistString.split("|");
if(!isNaN(parseInt(aTemp[0]))){
nLeft=aTemp[0];
}
if(!isNaN(parseInt(aTemp[1]))){
nTop=aTemp[1];
}
}
if(tf.U.getCookie(sInstance+"_visibility")=="block"){
sDisplay="block";
}
}catch(e){
}
}
var sIdToInspect=tf.U.getCookie(sInstance+"_idToInspect");
sIdToInspect=sIdToInspect==null?"":sIdToInspect;
var sB=[];
sB.push('<div id="');
sB.push(sDOMInstance);
sB.push('_container" class="nlCont" style="top:');
sB.push(nTop);
sB.push('px; right:');
sB.push(nRight);
sB.push('px;"  onmouseover="if(really_over(this)){');
sB.push(sInstance);
sB.push('.toggleDisplay();}" onmouseout="if(really_out(this)){');
sB.push(sInstance);
sB.push('.toggleDisplay();}">');
sB.push('<div id="');
sB.push(sDOMInstance);
sB.push('_handle" class="nlHandle" >0: Msgs</div>');
sB.push('<div id="');
sB.push(sDOMInstance);
sB.push('_body" class="nlBody" style="display:');
sB.push(sDisplay);
sB.push('"><div id="');
sB.push(sDOMInstance);
sB.push('_header" class="nlHeader"><span id="');
sB.push(sDOMInstance);
sB.push('_clear" class="nlClear" onclick="');
sB.push(sInstance);
sB.push('.clearLog()">clear</span></div><div id="');
sB.push(sDOMInstance);
sB.push('_logDisplay" class="nlLogDisp"></div><div id="');
sB.push(sDOMInstance);
sB.push('_footer" class="nlFooter">get html:<input id="');
sB.push(sDOMInstance);
sB.push('_idToInspect" style="font-size:9px; height:18px;" value="');
sB.push(sIdToInspect);
sB.push('" size=42/> <span id="');
sB.push(sDOMInstance);
sB.push('_go" style="color: blue;" onclick="');
sB.push(sInstance);
sB.push('.getHTML()">go</span><textarea id="');
sB.push(sDOMInstance);
sB.push('_textArea" style="width:95%; height: 40px; font-size:9px;"></textarea></div></div></div></div>');
document.write(sB.join(''));
_gE(sDOMInstance+"_clear").style.cursor="pointer";
_gE(sDOMInstance+"_go").style.cursor="pointer";
savePos=function(o,pX,pY,ev){
if(o.id==sDOMInstance+"_container"){
tf.U.setCookie(sInstance+"_position",+pX+"|"+pY);
}
};
edEnableDrag(sDOMInstance+'_container',null,null,this.savePos);
bLoggerConfigured=true;
}catch(e){
alert("Code-level error initializing edNLog: "+e.description);
}
}
}
};
debug=edNLog.debug;
